import 'package:animated_custom_dropdown/custom_dropdown.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:yuan_hang_app/bean/dict_entity.dart';
import 'package:yuan_hang_app/bean/exterior_entity.dart';
import 'package:yuan_hang_app/bean/interior_entity.dart';
import 'package:yuan_hang_app/bean/version_entity.dart';
import 'package:yuan_hang_app/res/w_colors.dart';
import 'package:yuan_hang_app/res/w_constant.dart';
import 'package:yuan_hang_app/res/w_dimens.dart';
import 'package:yuan_hang_app/utils/size_utils.dart';
import 'package:yuan_hang_app/utils/common_req_utils.dart';
import 'package:yuan_hang_app/utils/string_utils.dart';
import 'package:yuan_hang_app/views/home/view/leads/widget/common_date.dart';
import 'package:yuan_hang_app/views/home/view/order/order_model.dart';
import 'package:yuan_hang_app/widget/label_item.dart';
import 'package:yuan_hang_app/widget/w_text.dart';
import 'package:flustars/flustars.dart';
import 'package:yuan_hang_app/widget/w_toast.dart';

import '../views/report/model/region_info.dart';

enum SortType {
  LEADS_POOL, //线索池
  LEADS_ASSIGN, //线索分配
  LEADS_FOLLOW_UP, //线索跟进
  DEFEAT_AUDIT, ////战败审核
  DEFEAT_LEADS_POOL, //战败线索池
  BOOK_DRIVE, //预约试驾
  BOOKING, //试驾预约
  DRIVE_BACK, //试驾回访
  ORDER_MANAGER, //代客下单
  CAR_STORE, //车辆库存
  CORE_RATE_REPORT, //核心四率报表
  LEADS_OPERATION_REPORT, //线索运营报表
  LEADS_SOURCE_REPORT, //线索来源渠道分布报表
  SALES_REPORT, //销售占比分布报表
  SALESMAN_REPORT,
  SALES_ORDER//销售顾问业绩统计报表
}

class SortContent extends StatefulWidget {
  final SortType sortType;

  final Map? params;

  Function(Map params, bool isReset)? onSelected;

  final double buttonWidth;

  final double buttonHeight;

  SortContent(
      {super.key,
      this.sortType = SortType.LEADS_POOL,
      this.params,
      this.buttonWidth = 100,
      this.buttonHeight = 40,
      this.onSelected});

  @override
  State<SortContent> createState() => _SortContentState();
}

class _SortContentState extends State<SortContent> {
  Map params = {};
  List<Map> versionList = [];
  List<Map> exteriorList = [];
  List<Map> innerList = [];
  String exteriorId = "";
  String modelId = "";
  TextEditingController? _textController;

  //大区列表
  List<Map> regionList = [];

  //省份列表
  List<RegionInfo> provinceList = [];

  //城市列表
  List<RegionInfo> cityList = [];
  final _pController = SingleSelectController<RegionInfo>(null);
  final _cController = SingleSelectController<RegionInfo>(null);

  final _selectController = SingleSelectController<dynamic>(null);

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    params = widget.params ?? {};
    print("初始参数值: ${params}");

    getModelInfo();
    if (widget.sortType == SortType.CORE_RATE_REPORT) {
      getRegionList();
      getProvinceList();
    }
    if (widget.sortType == SortType.LEADS_SOURCE_REPORT ||
        widget.sortType == SortType.LEADS_OPERATION_REPORT ||
        widget.sortType == SortType.SALES_REPORT) {
      getRegionList();
    }
    if (widget.sortType == SortType.CAR_STORE) {
      _textController = TextEditingController.fromValue(
          TextEditingValue(text: params["vin"] ?? ""));
    }
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisSize: MainAxisSize.min,
      children: [
        Expanded(
          child: SingleChildScrollView(
              padding: EdgeInsets.zero,
              //  physics: const NeverScrollableScrollPhysics(),
              child: _sortWidget()),
        ),
        SizedBox(height: 10.px),
        Row(
          crossAxisAlignment: CrossAxisAlignment.end,
          children: [
            GestureDetector(
              onTap: () {
                _pController.clear();
                _cController.clear();
                print("reset params: ${params}");
                for (var key in params.keys) {
                  // 根据需要修改对应的值
                  params[key] = null;
                }
                //params.forEach((key, _) => params[key] = null);
                setState(() {});
                if (widget.onSelected != null) {
                  widget.onSelected!(params, true);
                }
              },
              child: Container(
                height: (widget.buttonHeight - 2).px,
                width: widget.buttonWidth.px,
                alignment: Alignment.center,
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(widget.buttonHeight.px),
                    border: Border.all(color: WColors.border, width: 1.px),
                    color: WColors.white),
                child: WText(
                  "重置",
                  style:
                      TextStyle(color: WColors.mainTextColor, fontSize: 14.px),
                ),
              ),
            ),
            Expanded(
              child: GestureDetector(
                onTap: () {
                  if (widget.onSelected != null) {
                    widget.onSelected!(params, false);
                  }
                },
                child: Container(
                  margin: EdgeInsets.only(left: 10.px),
                  height: widget.buttonHeight.px,
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                      borderRadius:
                          BorderRadius.circular(widget.buttonHeight.px),
                      color: WColors.primaryColor),
                  child: WText(
                    "确定",
                    style: TextStyle(color: WColors.white, fontSize: 14.px),
                  ),
                ),
              ),
            )
          ],
        )
      ],
    );
  }

  void getModelInfo() {
    if (params["configModel"] == null) {
      return;
    }
    modelId = OrderModel.getId(WConstant.modelList, params["configModel"]);
    params["configSer"] = "";
    params["configColor"] = "";
    params["configTrim"] = "";
    Toast.showLoading();
    getVersionByModeId();
    getExteriorModelById();
  }

  void getRegionList() {
    CommonReqUtils.getRegionList().then((list) {
      Toast.dismissLoading();
      regionList = list;
      setState(() {});
    });
  }

  void getProvinceList() {
    CommonReqUtils.getProvinceList().then((data) {
      Toast.dismissLoading();
      provinceList = data
          .map((item) =>
              RegionInfo(item["regionName"], item["regionId"].toString()))
          .toList();
      if (params["provinceId"] != null) {
        RegionInfo selectedInfo = provinceList
            .where((item) => item.regionId == params["provinceId"])
            .first;
        _pController.value = selectedInfo;
        getCityList(params["provinceId"]);
      }
      setState(() {});
    });
  }

  void getCityList(provinceId) {
    cityList = [];
    CommonReqUtils.getCityList(provinceId).then((data) {
      Toast.dismissLoading();
      cityList = data
          .map((item) =>
              RegionInfo(item["regionName"], item["regionId"].toString()))
          .toList();
      if (params["cityId"] != null) {
        RegionInfo selectedInfo =
            cityList.where((item) => item.regionId == params["cityId"]).first;
        _cController.value = selectedInfo;
      }
      setState(() {});
    });
  }

  void getVersionByModeId() {
    CommonReqUtils.getVersionByModeId(modelId).then((value) {
      Toast.dismissLoading();
      versionList = VersionEntity.exchangeLabelList(value);
      setState(() {});
    });
  }

  void getExteriorModelById() {
    CommonReqUtils.getExteriorModelById(modelId).then((value) {
      Toast.dismissLoading();
      exteriorList = ExteriorEntity.exchangeLabelList(value);
      setState(() {});
    });
  }

  void getInteriorModelById() {
    Toast.showLoading();
    CommonReqUtils.getInteriorModelById(exteriorId).then((inner) {
      Toast.dismissLoading();
      innerList = InteriorEntity.exchangeLabelList(inner);
      setState(() {});
    });
  }

  Widget _sortWidget() {
    if (widget.sortType == SortType.LEADS_POOL) {
      return Column(
        children: [
          _sortItem("线索来源", list: WConstant.leaderSourceLst),
          _sortItem("意向车型", list: WConstant.modelList),
          _sortItem("线索创建时间", isDate: true),
        ],
      );
    } else if (widget.sortType == SortType.LEADS_ASSIGN) {
      return Column(
        children: [
          _commonSort(),
          _sortItem("线索创建时间", isDate: true),
          _sortItem("计划跟进时间", isDate: true)
        ],
      );
    } else if (widget.sortType == SortType.LEADS_FOLLOW_UP) {
      return Column(
        children: [
          _sortItem("意向级别", list: WConstant.intentRangeList),
          _sortItem("意向车型", list: WConstant.modelList),
          _sortItem("线索来源", list: WConstant.leaderSourceLst),
          if (WConstant().userInfo.roleCode == "DZ")
            _sortItem("跟进顾问", list: WConstant().salesmanList),
          _sortItem("线索创建时间", isDate: true),
          _sortItem("计划跟进时间", isDate: true),
        ],
      );
    } else if (widget.sortType == SortType.DEFEAT_AUDIT) {
      ///、线索状态、线索来源、意向车型、跟进顾问、线索创建时间、申请时间
      return Column(
        children: [
          //   _sortItem("状态", list: WConstant.leadsStatusList.where((item) =>item["label"]=="战败申请").toList()),
          _sortItem("线索来源", list: WConstant.leaderSourceLst),
          _sortItem("意向车型", list: WConstant.modelList),
          if (WConstant().userInfo.roleCode == "DZ")
            _sortItem("跟进顾问", list: WConstant().salesmanList),
          _sortItem("线索创建时间", isDate: true),
          _sortItem("申请时间", isDate: true),
        ],
      );
    } else if (widget.sortType == SortType.DEFEAT_LEADS_POOL) {
      ///线索来源、意向车型、线索创建时间、线索战败时
      return Column(
        children: [
          _sortItem("线索来源", list: WConstant.leaderSourceLst),
          _sortItem("意向级别", list: WConstant.intentRangeList),
          _sortItem("线索创建时间", isDate: true),
          _sortItem("线索战败时间", isDate: true),
        ],
      );
    } else if (widget.sortType == SortType.BOOK_DRIVE) {
      return Column(
        children: [
          _sortItem("试驾类型", list: WConstant.driveTypeList),
          _sortItem("试驾方式", list: WConstant.driveMethodList),
          _sortItem("试驾车型", list: WConstant.modelList),
          if (WConstant().userInfo.roleCode == "DZ")
            _sortItem("接待顾问", list: WConstant().salesmanList),
          _sortItem("试驾登记时间", isDate: true),
        ],
      );
    } else if (widget.sortType == SortType.BOOKING) {
      return Column(
        children: [
          _sortItem("预约类型", list: WConstant.appointTypeList),
          _sortItem("预约创建日期", isDate: true),
        ],
      );
    } else if (widget.sortType == SortType.DRIVE_BACK) {
      return Column(
        children: [
          _sortItem("试驾类型", list: WConstant.driveTypeList),
          _sortItem("试驾方式", list: WConstant.driveMethodList),
          _sortItem("试驾车型", list: WConstant.modelList),
          if (WConstant().userInfo.roleCode == "DZ")
            _sortItem("接待顾问", list: WConstant().salesmanList),
          _sortItem("试驾结束时间", isDate: true),
        ],
      );
    } else if (widget.sortType == SortType.ORDER_MANAGER) {
      return Column(
        children: [
          _sortItem("车型", list: WConstant.modelList),
          Offstage(
            offstage: versionList.isEmpty,
            child: _sortItem("版本", list: versionList),
          ),
          Offstage(
            offstage: exteriorList.isEmpty,
            child: _sortItem("外观", list: exteriorList),
          ),
          Offstage(
            offstage: innerList.isEmpty,
            child: _sortItem("内饰", list: innerList),
          ),
          _sortItem("订单创建日期", isDate: true),
        ],
      );
    } else if (widget.sortType == SortType.CAR_STORE) {
      return Column(
        children: [
          _sortInputItem("VIN"),
          _sortItem("车型", list: WConstant.modelList),
          _sortItem("订单状态", list: WConstant.storeOrderStatusList),
          _sortItem("车辆状态", list: WConstant.storeCarStatusList),
          _sortItem("配车状态", list: WConstant.storeMatchCarStatusList),
        ],
      );
    } else if (widget.sortType == SortType.CORE_RATE_REPORT) {
      return Column(
        children: [
          _sortItem("大区", list: regionList),
          _sortDropDown("省份", list: provinceList, isProvince: true),
          _sortDropDown("城市", list: cityList),
        ],
      );
    } else if (widget.sortType == SortType.LEADS_OPERATION_REPORT ||
        widget.sortType == SortType.LEADS_SOURCE_REPORT ||
        widget.sortType == SortType.SALES_REPORT) {
      return Column(
        children: [
          if (WConstant().userInfo.companyId == 1)
            _sortItem("大区", list: regionList),
          if (WConstant().userInfo.companyId == 1)
            _sortItem("直营店类型", list: WConstant.shopTypeList),
          _sortItem("统计时间", isDate: true),
        ],
      );
    } else if (widget.sortType == SortType.SALESMAN_REPORT) {
      return Column(
        children: [
          _sortItem("统计时间", isDate: true),
        ],
      );
    } else if (widget.sortType == SortType.SALES_ORDER) {
      return Column(
        children: [
          _sortInputItem("销售单号"),
          _sortItem("车型", list: WConstant.modelList),
          _sortItem("销售订单状态", list: WConstant.storeCarStatusList),
          if (WConstant().userInfo.roleCode == "DZ")
            _sortItem("归属销售顾问", list: WConstant().salesmanList),
          _sortItem("订单创建时间", isDate: true),
        ],
      );
    }
    return Container();
  }

  Widget _commonSort() {
    return Column(
      children: [
        _sortItem("意向级别", list: WConstant.intentRangeList),
        _sortItem("意向车型", list: WConstant.modelList),
        _sortItem("状态", list: getLeaderStatusList()),
        _sortItem("线索来源", list: WConstant.leaderSourceLst),
        _sortItem(widget.sortType == SortType.LEADS_FOLLOW_UP ? "跟进顾问" : "销售顾问",
            list: WConstant().salesmanList),
      ],
    );
  }

  List<Map> getLeaderStatusList() {
    List statusList = ["待分配", "待跟进", "跟进中"];
    return WConstant.leadsStatusList
        .where((item) => statusList.contains(item["label"]))
        .toList();
  }

  Widget _sortInputItem(String label) {
    return Padding(
      padding: EdgeInsets.only(bottom: 10.px),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          WText(
            label,
            style: TextStyle(
                fontSize: WDimens.tsLabel,
                color: WColors.mainTextColor,
                fontWeight: FontWeight.bold),
          ),
          Container(
            width: SizeUtils.screenW(),
            margin: EdgeInsets.only(top: 10.px),
            decoration: BoxDecoration(
                border: Border.all(color: WColors.border, width: 1.px),
                borderRadius: BorderRadius.circular(5.px)),
            child: TextField(
              keyboardAppearance: Brightness.light,
              autofocus: false,
              maxLength: 21,
              controller: _textController,
              textAlign: TextAlign.start,
              scrollPadding: EdgeInsets.zero,
              onChanged: (s) {
                if (label == "VIN") {
                  params["vin"] = s;
                } else if (label == "销售单号") {
                  params["orderCode"] = s;
                }
                setState(() {});
              },
              maxLines: 1,
              keyboardType: TextInputType.text,
              style: TextStyle(
                color: WColors.subTextColor,
                fontSize: WDimens.tsMedium,
              ),
              decoration: InputDecoration(
                counterText: "",
                isCollapsed: true,
                counterStyle: TextStyle(
                    color: WColors.hintTextColor, fontSize: WDimens.tsSmall),
                focusedBorder: const OutlineInputBorder(
                    borderSide:
                        BorderSide(width: 0, color: Colors.transparent)),
                disabledBorder: const OutlineInputBorder(
                    borderSide:
                        BorderSide(width: 0, color: Colors.transparent)),
                enabledBorder: const OutlineInputBorder(
                    borderSide:
                        BorderSide(width: 0, color: Colors.transparent)),
                border: OutlineInputBorder(
                    borderSide: BorderSide(width: 1.px, color: WColors.border)),
                hintText: "请输入$label",
                contentPadding:
                    EdgeInsets.symmetric(horizontal: 5.px, vertical: 8.px),
                hintStyle: TextStyle(color: WColors.CCCCCCC, fontSize: 12.px),
              ),
            ),
          )
        ],
      ),
    );
  }

  Widget _sortDropDown(String label,
      {List<RegionInfo>? list, bool? isProvince = false}) {
    return Padding(
        padding: EdgeInsets.only(bottom: 10.px),
        child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
          WText(
            label,
            style: TextStyle(
                fontSize: WDimens.tsLabel,
                color: WColors.mainTextColor,
                fontWeight: FontWeight.bold),
          ),
          CustomDropdown<RegionInfo>(
            hintText: '请选择',
            items: list,
            hideSelectedFieldWhenExpanded: true,
            controller: isProvince! ? _pController : _cController,
            onChanged: (value) {
              if (isProvince) {
                params["provinceId"] = value?.regionId;
                getCityList(value?.regionId);
                _cController.clear();
              } else {
                params["cityId"] = value?.regionId;
              }
              print("点击${params}");
            },
          ),
        ]));
  }

  Widget _sortItem(String label, {List<Map>? list, bool isDate = false}) {
    return Padding(
      padding: EdgeInsets.only(bottom: 10.px),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          WText(
            label,
            style: TextStyle(
                fontSize: WDimens.tsLabel,
                color: WColors.mainTextColor,
                fontWeight: FontWeight.bold),
          ),
          isDate
              ? Padding(
                  padding: EdgeInsets.only(top: 10.px),
                  child: Row(
                    children: [
                      Expanded(child: dateWidget(label: label)),
                      WText("  一  ",
                          style: TextStyle(
                              fontSize: WDimens.tsMedium,
                              color: WColors.border)),
                      Expanded(
                        child: dateWidget(isStart: false, label: label),
                      ),
                    ],
                  ),
                )
              : GridView.builder(
                  shrinkWrap: true,
                  physics: const NeverScrollableScrollPhysics(),
                  padding: EdgeInsets.only(top: 10.px),
                  itemBuilder: (context, index) => GestureDetector(
                    onTap: () {
                      unFocus(context);
                      if (isCheck(label, list?[index]["value"])) {
                        _itemClick(label, null);
                        return;
                      }

                      String val = list![index]["value"];
                      if (widget.sortType == SortType.ORDER_MANAGER) {
                        if (label == "车型") {
                          params["configModel"] = val;
                          getModelInfo();
                        } else if (label == "外观") {
                          exteriorId = OrderModel.getId(exteriorList, val);
                          params["configTrim"] = "";
                          getInteriorModelById();
                        }
                      }
                      _itemClick(label, val);
                      print("点击${params}");
                      setState(() {});
                    },
                    child: Container(
                      height: 24.px,
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          color: isCheck(label, list?[index]["value"])
                              ? WColors.primaryColor
                              : WColors.white,
                          borderRadius: BorderRadius.circular(20.px),
                          border: Border.all(
                              color: isCheck(label, list?[index]["value"])
                                  ? WColors.primaryColor
                                  : WColors.border,
                              width: 1.px)),
                      child: WText(list?[index]["label"],
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(
                              fontSize: WDimens.tsMedium,
                              color: isCheck(label, list?[index]["value"])
                                  ? WColors.white
                                  : WColors.mainTextColor)),
                    ),
                  ),
                  itemCount: list?.length,
                  gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                      mainAxisSpacing: 10.px,
                      crossAxisCount:
                          widget.sortType == SortType.ORDER_MANAGER &&
                                  label == "版本"
                              ? 3
                              : 4,
                      crossAxisSpacing: 10.px,
                      childAspectRatio:
                          widget.sortType == SortType.ORDER_MANAGER &&
                                  label == "版本"
                              ? 3.2
                              : 2.5),
                )
        ],
      ),
    );
  }

  Widget dateWidget({bool isStart = true, String label = ""}) {
    Map keys = _getDateKey(label, isStart: isStart);
    String key = isStart ? keys['start'] : keys['end'];
    return GestureDetector(
      onTap: () {
        unFocus(context);
        showDateSelect(keys).then((selectTime) {
          if (selectTime != null && selectTime.length > 0) {
            String selectStart =
                DateUtil.formatDate(selectTime[0], format: DateFormats.y_mo_d);
            // //选择结果中的结束时间
            String selectEnd =
                DateUtil.formatDate(selectTime[1], format: DateFormats.y_mo_d);
            params[keys['start']] = selectStart;
            params[keys['end']] = selectEnd;
            setState(() {});
            print("点击${params}");
          }
        });
      },
      child: Container(
        height: 36.px,
        alignment: Alignment.center,
        padding: EdgeInsets.symmetric(horizontal: 5.px),
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(5.px),
            border: Border.all(color: WColors.border, width: 1.px)),
        child: Row(
          children: [
            Image.asset(
              "images/ic_calendar.png",
              width: 20.px,
            ),
            SizedBox(
              width: 5.px,
            ),
            Expanded(
                child: WText(params[key] ?? "请选择",
                    style: TextStyle(
                        fontSize: WDimens.tsMedium,
                        color: params[key] == null
                            ? WColors.hintTextColor
                            : WColors.mainTextColor))),
            Offstage(
              offstage: StringUtils.isEmpty(params[key]),
              child: GestureDetector(
                onTap: () {
                  isStart
                      ? params[keys['start']] = null
                      : params[keys['end']] = null;
                  setState(() {});
                },
                child: Image.asset(
                  "images/ic_del_grey.png",
                  width: 16.px,
                ),
              ),
            )
          ],
        ),
      ),
    );
  }

  Future showDateSelect(Map keys) {
    //获取当前的时间
    DateTime start = params[keys['start']] != null
        ? DateTime.parse(params[keys['start']])
        : DateTime.now();
    //在当前的时间上多添加4天
    DateTime end = params[keys['end']] != null
        ? DateTime.parse(params[keys['end']])
        : DateTime(start.year, start.month, start.day + 4);

    return CommonDate.showPicker(
      context: context,
      pickerType: PickerType.range,
      value: [start, end],
      firstDate: DateTime(start.year - 10, 1, 1),
      //结束时间
      lastDate: DateTime(start.year + 10, 12, 31),
    );
  }

  unFocus(BuildContext mContext) {
    final otherNode = FocusNode();
    FocusScope.of(mContext).requestFocus(otherNode);
    otherNode.unfocus();
  }

  void _itemClick(label, code) {
    if (label == "线索来源") {
      params["clueSource"] = code;
    } else if (label == "意向车型") {
      params["modelId"] = code;
    } else if (label == "意向级别") {
      params["level"] = code;
    } else if (label == "状态") {
      params["status"] = code;
    } else if (label == "销售顾问" || label == "跟进顾问") {
      params["saleman"] = code;
    }
    // else if (label == "客户标签") {
    //   params["tag"] = code;
    // }
    //
    else if (label == "试驾类型") {
      params["driveType"] = code;
    } else if (label == "试驾方式") {
      params["driveMethod"] = code;
    } else if (label == "试驾车型") {
      params["modelId"] = code;
    } else if (label == "接待顾问") {
      params["saleMan"] = code;
    } else if (label == "车型") {
      if (SortType.CAR_STORE == widget.sortType || SortType.SALES_ORDER == widget.sortType) {
        params["modelCode"] = code;
      } else {
        params["configModel"] = code;
      }
    } else if (label == "版本") {
      params["configVersion"] = code;
    } else if (label == "外观") {
      params["configColor"] = code;
    } else if (label == "内饰") {
      params["configTrim"] = code;
    } else if (label == "预约类型") {
      params["appointType"] = code;
    } else if (label == "订单状态") {
      params["orderType"] = code;
    } else if (label == "车辆状态") {
      params["lifeCycle"] = code;
    } else if (label == "配车状态") {
      params["vhclMatchStatus"] = code;
    } else if (label == "大区") {
      params["regionId"] = code;
    } else if (label == "直营店类型") {
      params["dealerType"] = code;
    } else if (label == "销售订单状态") {
      params["status"] = code;
    } else if (label == "归属销售顾问") {
      params["saleman"] = code;
    }

    setState(() {});
  }

  bool isCheck(label, code) {
    if (label == "线索来源") {
      return params["clueSource"] == code;
    } else if (label == "意向车型") {
      return params["modelId"] == code;
    } else if (label == "意向级别") {
      return params["level"] == code;
    } else if (label == "状态") {
      return params["status"] == code;
    } else if (label == "销售顾问" || label == "跟进顾问") {
      return params["saleman"] == code;
    } else if (label == "预约类型") {
      return params["appointType"] == code;
    }
    // else if (label == "客户标签") {
    //   return params["tag"] == code;
    // }

    else if (label == "试驾类型") {
      return params["driveType"] == code;
    } else if (label == "试驾方式") {
      return params["driveMethod"] == code;
    } else if (label == "试驾车型") {
      return params["modelId"] == code;
    } else if (label == "接待顾问") {
      return params["saleMan"] == code;
    } else if (label == "车型") {
      if (SortType.CAR_STORE == widget.sortType || SortType.SALES_ORDER == widget.sortType) {
        return params["modelCode"] == code;
      } else {
        return params["configModel"] == code;
      }
    } else if (label == "版本") {
      return params["configVersion"] == code;
    } else if (label == "外观") {
      return params["configColor"] == code;
    } else if (label == "内饰") {
      return params["configTrim"] == code;
    } else if (label == "订单状态") {
      return params["orderType"] == code;
    } else if (label == "车辆状态") {
      return params["lifeCycle"] == code;
    } else if (label == "配车状态") {
      return params["vhclMatchStatus"] == code;
    } else if (label == "大区") {
      return params["regionId"] == code;
    } else if (label == "直营店类型") {
      return params["dealerType"] == code;
    } else if (label == "销售订单状态") {
      return params["status"] == code;
    } else if (label == "归属销售顾问") {
      return params["saleman"] == code;
    }

    return false;
  }

  Map _getDateKey(label, {isStart = true}) {
    Map keys = {"start": "beginDate", "end": "endDate"};
    if (label == "线索创建时间") {
      keys = {"start": "beginDate", "end": "endDate"};
    } else if (label == "计划跟进时间") {
      keys = {"start": "beginNextFollowDate", "end": "endNextFollowDate"};
    } else if (label == "申请时间") {
      keys = {"start": "beginApplyDate", "end": "endApplyDate"};
    } else if (label == "线索战败时间") {
      keys = {"start": "beginExamineDate", "end": "endExamineDate"};
    } else if (label == "试驾登记时间") {
      keys = {"start": "createdAtBegin", "end": "createdAtEnd"};
    } else if (label == "试驾结束时间") {
      keys = {"start": "endDriveTimeBegin", "end": "endDriveTimeEnd"};
    } else if (label == "订单创建日期") {
      keys = {"start": "orderCreateTimeBegin", "end": "orderCreateTimeEnd"};
    } else if (label == "预约创建日期") {
      keys = {"start": "createdAtBegin", "end": "createdAtEnd"};
    } else if (label == "统计时间") {
      keys = {"start": "startTime", "end": "endTime"};
    } else if (label == "订单创建时间") {
      keys = {"start": "startTime", "end": "endTime"};
    }
    return keys;
  }
}
